package com.ruoyi.pc.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.pc.service.ILbCompanyDeviceService;
import com.ruoyi.pc.domain.LbCompanyDevice;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 公司和设备关联关系Controller
 * 
 * @author ruoyi
 * @date 2020-06-21
 */
@RestController
@RequestMapping("/companydevice")
public class LbCompanyDeviceController extends BaseController
{
    @Autowired
    private ILbCompanyDeviceService lbCompanyDeviceService;

    /**
     * 查询公司和设备关联关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:companydevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(LbCompanyDevice lbCompanyDevice)
    {
        startPage();
        List<LbCompanyDevice> list = lbCompanyDeviceService.selectLbCompanyDeviceList(lbCompanyDevice);
        return getDataTable(list);
    }

    /**
     * 导出公司和设备关联关系列表
     */
    @PreAuthorize("@ss.hasPermi('business:companydevice:export')")
    @Log(title = "公司和设备关联关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LbCompanyDevice lbCompanyDevice) throws IOException
    {
        List<LbCompanyDevice> list = lbCompanyDeviceService.selectLbCompanyDeviceList(lbCompanyDevice);
        ExcelUtil<LbCompanyDevice> util = new ExcelUtil<LbCompanyDevice>(LbCompanyDevice.class);
        util.exportExcel(response, list, "companydevice");
    }

    /**
     * 获取公司和设备关联关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:companydevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lbCompanyDeviceService.selectLbCompanyDeviceById(id));
    }

    /**
     * 新增公司和设备关联关系
     */
    @PreAuthorize("@ss.hasPermi('business:companydevice:add')")
    @Log(title = "公司和设备关联关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LbCompanyDevice lbCompanyDevice)
    {
        return toAjax(lbCompanyDeviceService.insertLbCompanyDevice(lbCompanyDevice));
    }

    /**
     * 修改公司和设备关联关系
     */
    @PreAuthorize("@ss.hasPermi('business:companydevice:edit')")
    @Log(title = "公司和设备关联关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LbCompanyDevice lbCompanyDevice)
    {
        return toAjax(lbCompanyDeviceService.updateLbCompanyDevice(lbCompanyDevice));
    }

    /**
     * 删除公司和设备关联关系
     */
    @PreAuthorize("@ss.hasPermi('business:companydevice:remove')")
    @Log(title = "公司和设备关联关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lbCompanyDeviceService.deleteLbCompanyDeviceByIds(ids));
    }
}
